<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片试图 -->
    <el-card>
      <!-- 搜索框 -->
      <el-row :gutter="20">
        <el-col :span="10">
          <div class="grid-content bg-purple">
            <el-input
              placeholder="请输入内容"
              class="input-with-select"
              v-model="queryInfo.query"
              clearable
              @clear="getOrderList"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getOrderList"
              ></el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>
      <!-- 订单表格 -->
      <el-table
        :data="orderList"
        style="width: 100%"
        border
      >
        <el-table-column
          type="index"
          label="#"
          width="50px"
        ></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="300px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="180px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款"
          align="center"
        >
          <template v-slot:default="scope">
            <el-tag
              type="success"
              v-if="scope.row.order_pay === 1"
            >已付款</el-tag>
            <el-tag
              type="danger"
              v-else
            >未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间"
          width="300px"
          align="center"
        >
          <template v-slot:default="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column
          label="操作"
          width="180"
          align="center"
        >
          <!-- eslint-disable-next-line vue/no-unused-vars -->
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showAddressDialog"
            ></el-button>
            <!-- 地址按钮 -->
            <el-button
              type="success"
              icon="el-icon-location-information"
              size="mini"
              @click="showProgressDialog(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 地址修改对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="addressVisible"
      width="60%"
      @close="handleClose"
    >
      <el-form
        :model="addressForm"
        :rules="addressRules"
        ref="addressRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item
          label="省市区/县"
          prop="value"
        >
          <el-cascader
            v-model="addressForm.value"
            :options="citydata"
            :props="props"
          ></el-cascader>
        </el-form-item>
        <el-form-item
          label="详细地址"
          prop="addressMeg"
        >
          <el-input v-model="addressForm.addressMeg"></el-input>
        </el-form-item>
      </el-form>

      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="addressVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息 -->
    <el-dialog
      title="提示"
      :visible.sync="progressVisible"
      width="50%"
    >
      <span>这是一段信息</span>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="progressVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata.js'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      // 订单列表
      orderList: [],
      // 订单总数
      total: 0,
      // 地址修改对话框
      addressVisible: false,
      props: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      citydata,
      addressForm: {
        value: [],
        addressMeg: ''
      },
      addressRules: {
        valus: [
          { required: true, message: '请选择地址', trigger: 'blur' }
        ],
        addressMeg: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }

        ]
      },
      // 物流信息
      progressVisible: false,
      progressInfo: []
    }
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders',
        { params: this.queryInfo })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      // console.log(res.data)
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrderList()
    },
    // 地址修改对话框
    showAddressDialog () {
      this.addressVisible = true
    },
    handleClose () {
      this.$refs.addressRef.resetFields()
    },
    // 物流信息展示
    async showProgressDialog (row) {
      // console.log(row)
      // const { data: res } = await this.$http.get('/kuaidi/47')
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取物流信息失败')
      // }
      // this.progressInfo = res.data
      // console.log(this.progressInfo)
      this.progressVisible = true
    }

  },
  created () {
    this.getOrderList()
  }
}
</script>

<style lang="less" scoped>
</style>
